﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ltModel.Model;
using ltModel.BLL;
using ltModel;

public partial class ProjectAdd : System.Web.UI.Page
{
    ltModel.BLL.ProjectBLL projectBLL = new ltModel.BLL.ProjectBLL();
    ProjectStreetBLL projectStreetBLL = new ProjectStreetBLL();
    ProjectTypeBLL projectTypeBLL = new ProjectTypeBLL();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            List<ProjectStreet> listStreet = projectStreetBLL.GetList();
            ddlStreet.DataSource = listStreet;
            ddlStreet.DataTextField = "StreetName";
            ddlStreet.DataValueField = "StreetID";
            ddlStreet.DataBind();


            List<ProjectType> listType = projectTypeBLL.GetList();
            ddlType.DataSource = listType;
            ddlType.DataTextField = "TypeName";
            ddlType.DataValueField = "TypeID";
            ddlType.DataBind();
        }
    }
    protected void iBtnAdd_Click(object sender, ImageClickEventArgs e)
    {
        ltModel.Model.Project project = new ltModel.Model.Project();

        project.ProjectName = DataProtector.ToSBC(txbProjectName.Text.Trim());
        project.Organizer = DataProtector.ToSBC(txbOrganizor.Text.Trim());
        project.ServiceLocation = DataProtector.ToSBC(txbServiceLocation.Text.Trim());
        project.ProjectContent = DataProtector.ToSBC(txbProjectContent.Text.Trim());
        project.RecruitmentLocation = DataProtector.ToSBC(txbRecruitmentLocation.Text.Trim());
        project.RecruitmentAmount = DataProtector.ToSBC(txbRecruitmentAmount.Text);
        project.RegistrationDeadLine = rdpRegistrationDeadLine.SelectedDate.Value;
        project.RegistrationRequirement = DataProtector.ToSBC(txbRegistrationRequirement.Text.Trim());
        project.Contact = DataProtector.ToSBC(txbContact.Text.Trim());
        project.ProjectStreetID = Convert.ToInt32(ddlStreet.SelectedValue);
        project.ProjectTypeID = Convert.ToInt32(ddlType.SelectedValue);

        string file = fileUpload.SaveFiles();
        if (!string.IsNullOrEmpty(file))
            project.Attachment = file;

        if (projectBLL.Add(project) > 0)
        {
            ltModel.MessageBox.ShowAndRedirect(this, "项目申请提交成功", Request.Url.ToString());
        }
        else
            ltModel.MessageBox.ResponseScript(this, "alert('网络繁忙，请稍后再试！');history.back()");
    }
    protected void iBtnReset_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect(Request.Url.ToString());
    }
}